package com.koron.css2.meterService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.meterService.bean.query.MsVerifyQueryBean;
import com.koron.css2.meterService.dto.MsVerifyDto;
import com.koron.css2.meterService.mapper.MsVerifyMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * 校表列表
 * @author 周利斌
 *
 */
public class MsVeriList implements ServerInterface{
	
	private static Logger log = LogManager.getLogger(MsVeriList.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PageInfo.class);
		try {
			MsVerifyQueryBean bean = JsonUtils.objectToPojo(req.getData(), MsVerifyQueryBean.class);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			MsVerifyMapper mapper = factory.getMapper(MsVerifyMapper.class);

			List<MsVerifyDto> list = mapper.selectMsVerifyList(bean);


			Map<String, String> checks = Tools.mapDicByCode(factory, "RCN"); //检查结果
			//Map<String, String> handWays = Tools.mapDicByCode(factory, "OMD"); //旧表处理方式

	//		Map<String, String> cashs = Tools.mapDicByCode(factory, "BPW");  //缴费方式
			Map<String, String> meterTypes = Tools.mapDicByCode(factory, "MMT"); //水表类型
			list.forEach(t -> {
				t.setProcessStateName(Tools.transProcessStatus(t.getProcessState()));
//				if(t.getOldHandleWay() != null) {
//					t.setOldHandleWayName(handWays.get(t.getOldHandleWay()));
//				}
//				if(t.getCashPledgeRefundWay() != null) {
//					t.setCashPledgeRefundWayName(cashs.get(t.getCashPledgeRefundWay().toString()));
//				}
				if(t.getCheckResult() != null) {
					t.setCheckResultName(checks.get(t.getCheckResult()));
				}
				if(t.getMeterType() != null) {
					t.setMeterTypeName(meterTypes.get(t.getMeterType()));
				}
			});
			info.setData(new PageInfo<MsVerifyDto>(list));
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("查询失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}

}
